﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AlterAnnouncement : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //GridView_Announcement.Visible = true;
        GridView_Announcement.DataBind();
        //DetailsView1.Visible = false;
        //DetailsView1.Visible = true;
        lblConfirm.Text = "";
        
       
    }

    protected void GridView_Announcement_SelectedIndexChanged(object sender, EventArgs e)
    {
        //DetailsView1.Visible = true;
        DetailsView1.ChangeMode(DetailsViewMode.Edit);
        DetailsView1.DataBind();
        //GridView_Announcement.Visible = false;
    }

    protected void DetailsView1_onItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        try
        {
            Announcement a = new Announcement();
            a.AnnouncementID = int.Parse(DetailsView1.DataKey.Value.ToString().Trim()) ;
            a.Title = DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim();
            a.Description = DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim();
            //a.DatePosted = Convert.ToDateTime(DetailsView1.Rows[0].Cells[0].Controls[0].ToString());
            //a.EmployeeID = int.Parse(DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim());

            ManageAnnouncement ma = new ManageAnnouncement();
            ma.updateAnnouncementLibrarianView(a);
        }
        catch (Exception ex)
        {
            //lblConfirm.Text = ex.Message.ToString();
        }
        lblConfirm.Text = "Your record has been saved";

        //DetailsView1.Visible = false;
        //GridView_Announcement.Visible = true;
        
    }

    protected void DetailsView1_onItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        GridView_Announcement.DataBind();
    }

    protected void DetailsView1_onItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        try
        {
            Announcement a = new Announcement();
            a.AnnouncementID = int.Parse(DetailsView1.DataKey.Value.ToString().Trim());
            a.Title = DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim();
            a.Description = DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim();
            a.DatePosted = Convert.ToDateTime(DetailsView1.Rows[0].Cells[0].Controls[0].ToString());
            a.EmployeeID = int.Parse(DetailsView1.Rows[0].Cells[0].Controls[0].ToString().Trim());

            ManageAnnouncement ma = new ManageAnnouncement();
            //ma.updateAnnouncementLibrarianView(a);
        }
        catch(Exception ex)
        {
            lblConfirm.Text = "Your record has been saved";
        }
    }

    protected void btnNew_Click(object sender, EventArgs e)
    {
        //DetailsView1.Visible = true;
        DetailsView1.ChangeMode(DetailsViewMode.Insert);
    }
}
